 # -*- coding: utf-8 -*-

import db
reload( db)
from db import McfConnector


class Relation():     
	"""Relation between two AE"""
	def __init__(self, libmyCF, relation_id, child, parent, retaltion_type_id): 
		self.libmyCF = libmyCF
		self.relation_id = relation_id
		self.child = child
		self.parent = parent
		self.relation_type_id = retaltion_type_id

	def getChildAE( self):
		return self.libmyCF.ontology.all_AEs[ self.child ]

	def getName( self):
		return self.libmyCF.ontology.all_relations_type[ self.relation_type_id ].getName()

	def getParentAE( self):
		return self.libmyCF.ontology.all_AEs[ self.parent ]


class Collection_of_Relations(list):
	"""Collection of Relations of a given AE"""
	def __init__(self,AE):
		#new version - without SQL query
		for relation in AE.onto.all_relations:
			if relation.child == AE.AE_id or relation.parent == AE.AE_id :
				self.append(relation)
